#include "stdio.h"
main()
{
	int n;
	int shu[14];
	char  ss[8],k;
	char yong[50];
	int i,j;
	
	scanf("%d",&n);
	while (n!=0)
	{
		memset(shu,0,sizeof(shu));
		for (i=1;i<=n;++i) scanf("%d",&shu[i]);
		for (i=1;i<n;++i)
			for (j=i+1;j<=n;++j)
				if (shu[i]>shu[j])
				{
					shu[0]=shu[i];
					shu[i]=shu[j];
					shu[j]=shu[0];
				}
	ss[0]=0;ss[1]=0;
	memset(yong,0,sizeof(yong));
	k=1;
	while (k>0)
	{
		++ss[k];
		if (k>6)
		{
			for (i=1;i<6;++i) printf("%d ",shu[ss[i]]);
			printf("%d\n",shu[ss[6]]);	
			--k;
			yong[ss[k]]=0;
		}
		else if (ss[k]>n)
		{
			--k;
			yong[ss[k]]=0;
		}
		else if ((yong[ss[k]]==0)&&(ss[k]>ss[k-1])) 
		{
			yong[ss[k]]=1;
			++k;
			ss[k]=0;
		}
	}
		scanf("%d",&n);
		if (n!=0) printf("\n");
	}
}
